#include <cstdio>

int data[101][101];

int main(int argc, char const* argv[])
{
    int row, col;
    scanf("%d %d", &row, &col);
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < col; j++) {
            scanf("%d", &data[i][j]);
        }
    }
    int bound = row + col - 1;
    for (int m = 0; m < bound; m++) {
        for (int i = 0; i <= m; i++) {
            if (i < row && m - i < col)
                printf("%d\n", data[i][m - i]);
        }
    }
    return 0;
}